/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.sll.engagemangsindex.job;

import javax.annotation.PostConstruct;
import se.sll.engagemangsindex.ejb.ConfigurationHolder;
import javax.ejb.EJB;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import lombok.extern.slf4j.Slf4j;
import se.sll.engagemangsindex.task.LogicalAddressesTask;

/**
 *
 * @author khaleddaham
 */
@Singleton
@Startup
@Slf4j
public class LogicalAddressessJob {

    @EJB private LogicalAddressesTask addressTask;
    @EJB private ConfigurationHolder configuration;

    /**
     * Uses EJB 3.1 timer service to schedule a job that fetches logical addresses from a service registry
     * these are cached and later used for sending notifications.
     */
    @Schedule(second = "0", minute = "*", hour = "*", persistent = false)
    @PostConstruct
    public void doWork() {
        addressTask.cacheLogicalAddresses(configuration.getServiceCatalogue());
    }

    /**
     * Used for mock tests.
     * @param task 
     */
    protected void setLogicalAddressTask(LogicalAddressesTask task) {
        this.addressTask = task;
    }

    /**
     * Used for mock tests.
     * @param holder 
     */
    protected void setConfigurationHolder(ConfigurationHolder holder) {
        this.configuration = holder;
    }
}